extends Node2D

var mgsIndex = 0
var msgs = ["3","2","1","Ready!","Go!"]

func _ready():
	$HUD.score = Global.total_score
	$HUD.show_lavel_name() # 显示关卡名称
	$ball.position = $ballPosition.position
	$player.position = $planePosition.position
	get_tree().paused = true
	$Timer.start()
	
func _on_ball_hit_zhuankuai():
	$HUD.add_score(1)
	pass 


func _on_Timer_timeout():
	if mgsIndex <msgs.size():
		$HUD.showMSG(msgs[mgsIndex])
		mgsIndex += 1
	elif mgsIndex == msgs.size():
		$HUD.showMSG(msgs[mgsIndex-1])
		mgsIndex = 0
		$Timer.stop()
		yield($HUD,"msgShowOver")
		get_tree().paused = false
		
	pass # Replace with function body.


func _on_ball_lost_ball():
	Global.total_score = $HUD.score # 记录这盘的总分
	$HUD.showMSG("GAME OVER")
	yield($HUD,"msgShowOver")
	get_tree().reload_current_scene() # 重新加载当前场景
	pass # Replace with function body.


	

# 本关结束
func _on_ball_finish_level():
	print("本关结束")
	Global.to_next_level() # 进入下一关
	pass
